#!/bin/sh
clear
cd /root
echo -e "************************************************"
echo -e "           欢迎使用FAS系统快速安装助手          "
echo -e "************************************************"
echo -e "请选择："
echo -e "\033[31m1. 安装FAS 3.0    ♪～(´ε｀　) \033[0m"
echo -e "\033[31m2. 重置防火墙 (解决冬云等服务器安装没网) ♪～(´ε｀　) \033[0m"
echo -e "\033[31m3. 关闭数据库服务 ♪～(´ε｀　)\033[0m"
echo -e "\033[31m4. 关闭负载机的扫描 ♪～(´ε｀　)\033[0m"
echo -e "\033[31m5. 添加TCP/UDP端口 ♪～(´ε｀　)\033[0m"
echo -e "\033[31m6. 主机/副机负载系统 ♪～(´ε｀　)\033[0m"

echo -n "请输入安装选项并回车："
read install_type
if [ $install_type == 1 ];then
	if [ ! -d "/var/www/html/" ]; then  
		mkdir /var/www/ >/dev/null 2>&1
		mkdir /var/www/html/ >/dev/null 2>&1
	fi
    rm -rf fast.bin >/dev/null 2>&1
	yum remove epel-release -y >/dev/null 2>&1
	cd /root && wget -q https://ghproxy.com/https://raw.githubusercontent.com/abaguai/OpenVPN/master/fas/fast.bin -O fast.bin && chmod 0777 fast.bin && ./fast.bin
	
	echo "如果完成后打开后台直接显示目录，请访问如下地址修复：https://www.dingd.cn/fixed.php"
	
    rm -rf fast.bin >/dev/null 2>&1
	exit 0
fi 
if [ $install_type == 2 ];then
    echo -e "重置防火墙如果您修改过web端口请改回来再重置 回车继续"
    read jixu
	setenforce 0
	iptables -F
	service iptables save
	iptables -A INPUT -s 127.0.0.1/32  -j ACCEPT
	iptables -A INPUT -d 127.0.0.1/32  -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 440 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 3389 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 1024 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 137 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 137 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 1194 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 1195 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 1196 -j ACCEPT
	iptables -A INPUT -p tcp -m tcp --dport 1197 -j ACCEPT
	iptables -A INPUT -p udp -m udp --dport 137 -j ACCEPT
	iptables -A INPUT -p udp -m udp --dport 138 -j ACCEPT
	iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
	iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
	iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
	iptables -t nat -A PREROUTING -p udp --dport 138 -j REDIRECT --to-ports 53
	iptables -t nat -A PREROUTING -p udp --dport 137 -j REDIRECT --to-ports 53
	iptables -t nat -A PREROUTING -p udp --dport 1194 -j REDIRECT --to-ports 53
	iptables -t nat -A PREROUTING -p udp --dport 1195 -j REDIRECT --to-ports 53
	iptables -t nat -A PREROUTING -p udp --dport 1196 -j REDIRECT --to-ports 53
	iptables -t nat -A PREROUTING -p udp --dport 1197 -j REDIRECT --to-ports 53
	iptables -t nat -A PREROUTING --dst 10.8.0.1 -p udp --dport 53 -j DNAT --to-destination 10.8.0.1:5353
	iptables -t nat -A PREROUTING --dst 10.9.0.1 -p udp --dport 53 -j DNAT --to-destination 10.9.0.1:5353
	iptables -t nat -A PREROUTING --dst 10.10.0.1 -p udp --dport 53 -j DNAT --to-destination 10.10.0.1:5353
	iptables -t nat -A PREROUTING --dst 10.11.0.1 -p udp --dport 53 -j DNAT --to-destination 10.11.0.1:5353
	iptables -t nat -A PREROUTING --dst 10.12.0.1 -p udp --dport 53 -j DNAT --to-destination 10.12.0.1:5353
	iptables -A INPUT -p udp -m udp --dport 5353 -j ACCEPT  
	iptables -P INPUT DROP
	iptables -t nat -A POSTROUTING -s 10.0.0.0/24  -j MASQUERADE
	iptables -t nat -A POSTROUTING -j MASQUERADE
	service iptables save
	exit 0
fi
if [ $install_type == 3 ];then
	service mariadb stop
	systemctl disable mariadb.service
	exit 0
fi
if [ $install_type == 4 ];then
	rm -rf /bin/jk.sh
    vpn restart
	exit 0
fi
if [ $install_type == 5 ];then
     wget -q https://ghproxy.com/https://raw.githubusercontent.com/abaguai/OpenVPN/master/fas/port.sh -O port.sh && chmod 0777 port.sh  && bash port.sh 
fi
if [ $install_type == 6 ];then
     wget -q https://ghproxy.com/https://raw.githubusercontent.com/abaguai/OpenVPN/master/fas/fasfz.bin -O fasfz.bin && chmod 0777 fasfz.bin && bash fasfz.bin 
fi